package com.kb.erp.service.impl;


import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kb.erp.entity.CRMSalesOrder;
import com.kb.erp.entity.DbErrorLog;
import com.kb.erp.entity.FlowChartQueue;
import com.kb.erp.entity.InvtInfo;
import com.kb.erp.mapper.sqlServer.CommonMapper;
import com.kb.erp.mapper.sqlServer.DbErrorLogMapper;
import com.kb.erp.mapper.sqlServer.InvtInfoMapper;
import com.kb.erp.service.CommonService;
import com.kb.erp.service.CrmService;
import com.kb.erp.service.HrService;
import com.kb.erp.service.ItmaNageService;
import com.kb.erp.util.MessageUtil;
import com.xxl.job.core.context.XxlJobHelper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

@Service
@DS("ITMANAGE")
@Slf4j
public class ItmaNageServiceImpl extends ServiceImpl<InvtInfoMapper, InvtInfo> implements ItmaNageService {

    @Resource
    private InvtInfoMapper invtInfoMapper;
    @Resource
    private HrService hrService;

    @Override
    public void synInvtInfo() {
        long startTime = System.currentTimeMillis(); // 记录开始时间
        List<InvtInfo> list = invtInfoMapper.synInvtInfo();
        if (CollectionUtil.isNotEmpty(list)) {
            for (InvtInfo invtInfo : list) {
                //根据名称查询部门信息
                InvtInfo info = hrService.queryDeptByName(invtInfo.getUseName(), invtInfo.getRkey());
                //更新部门信息
                if (info != null) {
                    invtInfoMapper.updateById(info);
                }
            }
        }
        long endTime = System.currentTimeMillis(); // 记录结束时间
        long duration = endTime - startTime; // 计算耗时

        log.info("同步完成，耗时: {} 秒", duration/1000);
    }
}
